<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link rel="stylesheet" href="../../layui/css/layui.css?v=1" media="all">
    <script src="../../js/jquery/1.x/jquery.js?v=1"></script>
    <script src="../../layui/layui.js?v=1" charset="utf-8"></script>
    <script src="../../js/config.js?v=1"></script>
    <script src="../../js/public.js?v=1"></script>
    <script src="../../js/function.js?v=1"></script>
    <link rel="stylesheet" href="../../css/public.css?v=1">
    <link rel="stylesheet" href="../../css/patient/fangshi.css?v=1">
</head>
<body>
<div class="container">
    <div class="search-box">
        <div class="table-body">
            <div class="table-title" style="border-bottom:1px solid #cccccc;">
                <div class="table-title-left">
                    <p>访视情况</p>
                </div>
                <div class="clear"></div>
            </div>
            <form class="layui-form">
                <table class="layui-table" lay-even lay-skin="nob" style="border-top:1px solid #cccccc;margin:0;" id="list-table" lay-filter="list-table">
                </table>
            </form>
        </div>
    </div>
    <div class="add-fangshi">
        <button type="button" id="add_fangshi">创建新访视</button>
        <p id="next_visit_at">建议V4时间：2020-06-05</p>
    </div>
</div>
<div class="fixed-container change-center-container" id="add_fixed">
    <div class="fixed-main">
        <div class="fixed-title">
            <p>创建新访视</p>
            <i class="layui-icon layui-icon-close fixed-main-close"></i>
        </div>
        <div class="fixed-form">
            <form class="layui-form">
                <div class="fixed-form-item">
                    <div class="layui-form-label">就诊时间</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" placeholder="请选择时间" id="add_fangshi_date">
                    </div>
                </div>
                <div class="fixed-form-item-confirm">
                    <button type="button" class="cancel">取消</button>
                    <button style="background:#4777E7;color:white;" type="button" class="submit">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    $(document).ready(function () {
            patient_id = getLocalStorage('patient_id');
        layui.use(['element', 'form', 'layer', 'laydate', 'laypage','table'], function () {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var laypage = layui.laypage;
            var table = layui.table;


            //创建访视时间
            var now = new Date();
            var year = parseInt(now.getFullYear());
            var month = parseInt(now.getMonth()+1);
            var day = now.getDate();
            var max_date = year+'-'+month+'-'+day;
            laydate.render({
                'elem':'#add_fangshi_date',
                'max':max_date
            })
            //新增标签
            $('#add_fangshi').click(function () {
                $('#add_fixed').show();
            })
            $('#add_fixed .fixed-main-close').click(function () {
                $('#add_fixed').hide();
            })
            $('#add_fixed .cancel').click(function () {
                $('#add_fixed').hide();
            })
            $('#add_fixed .submit').click(function(){
                var add_fangshi_date = $('#add_fangshi_date').val();
                if(add_fangshi_date == ''){
                    layer.msg('请选择就诊时间', {icon: 5, time: 1500});return false;
                }
                ajax_post(configUrl.visitLevel,{user_id:patient_id,visit_at:add_fangshi_date},(res)=>{
                    console.log(res);
                    if (res.status == 0) {
                        layer.msg('创建成功', {icon: 1, time: 1000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5, time: 1500});
                    }
                })
            })

            //获取标签列表
            var followList = '';
            var params = {
                'hosp_id':getLocalStorage('hosp_id'),
                'dept_id':getLocalStorage('dept_id'),
                'user_id':patient_id,
                'visit_level':1,
                'is_remind':0,
                'next_followup':'',
                'status':0,
                'remind_day':0,
                'remind_time':0,
            }

            getFangshi(patient_id);

            //获取数据
            function getFangshi(user_id){
                ajax_get(configUrl.fangshiList,{user_id:patient_id},(res)=>{
                    console.log(res);
                    if(res.status == 0) {
                        lists = res.data;
                        var listsTmp = [];
                        $.each(lists.data, function (index, item) {
                            console.log(index)
                            str = {
                                "visit_level":'V'+item.visit_level,
                                "visit_period_date":item.visit_period_date,
                                "visit_at":item.visit_at,
                                "complete_per":item.complete_per,
                                "href":index == 0?'<a href="./qss/qss1.html"><img src="../../img/chakan.png">查看</a>':'',
                            };
                            listsTmp.push(str)
                        });
                        table.render({
                            elem: "#list-table",
                            cols: [[ //标题栏
                                {field: 'visit_level', title: '访视阶段'},
                                {field: 'visit_period_date', title: '建议就诊时间'},
                                {field: 'visit_at', title: '就诊时间'},
                                {field: 'complete_per', title: '问卷完成度'},
                                {field: 'href', title: '问卷'},
                            ]]
                            , data: listsTmp
                            , page: true
                            , even: true
                        });
                        $('#next_visit_at').text('建议V'+lists.nex_visit_level+'时间：'+lists.next_visit_at)
                    }else{
                        //layer.msg(res.msg, {icon: 5, time: 1500});
                        $('#next_visit_at').hide();
                    }
                });
            }
        });
    })
</script>
</html>